package com.darren.euc.action.app;

import com.darren.euc.entity.PageBean;
import com.darren.euc.entity.ResponseJSON;
import com.darren.euc.service.ClientService;
import com.darren.euc.util.Kv;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static java.util.Arrays.asList;

/**
 * Created by JUECHENG at 2018/3/12 17:46.
 */
@Controller
@RequestMapping("/_client")
public class _ClientAction {

    @Autowired
    private ClientService clientService;

    /**
     * todo:企业类型
     */
    @ResponseBody
    @RequestMapping(value = "/type_data")
    public ResponseJSON typeData(){

        List list = asList(
            Kv.of("type", "").set("typeName", ""),
            Kv.of("type", "").set("typeName", "")
        );

        return new ResponseJSON().setData(list);
    }

    /**
     * 入住企业列表
     */
    @ResponseBody
    @RequestMapping(value = "/client_list")
    public ResponseJSON clientList(@RequestParam(name = "type",required = false)Integer type,
                                   @RequestParam(name = "pn",required = false, defaultValue = "1")Integer pn,
                                   @RequestParam(name = "ps",required = false, defaultValue = "10")Integer ps){

        Map para = new HashMap();
        para.put("type", type);

        PageBean page = clientService.findPage(para, pn, ps);
        return new ResponseJSON().setData(page);
    }

    /**
     * 企业详情
     */
    @ResponseBody
    @RequestMapping(value = "/client_detail")
    public ResponseJSON clientDetail(@RequestParam(name = "client_id") Integer client_id){

        Map map = clientService.clientDetail(client_id);
        return new ResponseJSON().setData(map);
    }


}
